package option;

import Book.Book;
import Book.BookList;

import java.util.Scanner;

public class Delect implements MY{
    @Override
    public void work(BookList booklist) {
        System.out.println("删除图书");
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入你要删除的图书名：");
        String name=scanner.nextLine();
        int size=booklist.getUsedSize();
        int pos=-1;
        int i=0;
        for (i=0;i<size;i++){
            Book book=booklist.getBooks(i);
            if(book.getName().equals(name))
            {
               pos=i;
               break;
            }
        }
        if(i==size){
            System.out.println("没有您要删除的图书");
            return;
        }
        int j=pos;
        for(j=pos;j<size-1;j++){
            Book book=booklist.getBooks(j+1);
            booklist.setBooks(j,book);
        }
        booklist.setBooks(j,null);
        booklist.setUsedSize(size-1);

    }
}
